'use strict';
//获取数据库的引用
const db = uniCloud.database(); 
//获取集合的引用 表
const ratecollection = db.collection('help');
exports.main = async (event, context) => {
let type = event.type;
if(type == 0){
//老人打分
	if(event.eventId){
		let findres = await ratecollection.where({
		    _id:event.eventId,
		}).get()
		//找到该事件
		if(findres.affectedDocs == 1){
		let helpId = findres.data[0]._id;
		let updataRes = await ratecollection.doc(helpId).update({
			oldRate:event.rateValu,
		});
		}
		return findres
	}
	
}else{
//志愿者打分
console.log(event.rateValu)
console.log(event.eventId)
	if(event.eventId){
		let findres = await ratecollection.where({
		    _id:event.eventId,
		}).get()
	console.log(findres)
		//找到该事件
		if(findres.affectedDocs == 1){
			let helpId = findres.data[0]._id;
		let updataRes = await ratecollection.doc(helpId).update({
			volunRate:event.rateValu,
		});
			
		}
		return findres
	}
	
}

};
